<?php

namespace app\models\marketing;

use Yii;

/**
 * This is the model class for table "marketing_group".
 *
 * @property int $id
 * @property int $start_up_pool 创业池比率
 * @property int $dividend_pool 分红池比率
 * @property int $win_total 中奖人数(得产品)
 * @property float $no_win_commission 不中返多少佣金
 * @property int $vip2_recommend_finish_group_total 大团长直推成团人, 可以拿成团长
 * @property float $vip2_recommend_finish_group_award 成团奖, 百分比(大团长推荐)
 * @property int $card_total 集齐多少张蜜卡, 可分红
 * @property int $time 开团时间/分钟
 * @property int $quantity 成团人数
 */
class MarketingGroup extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'marketing_group';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['start_up_pool', 'dividend_pool', 'win_total', 'vip2_recommend_finish_group_total', 'card_total'], 'integer'],
            [['no_win_commission', 'vip2_recommend_finish_group_award'], 'number'],

            [['time', 'quantity'], 'safe']
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'start_up_pool' => 'Start Up Pool',
            'dividend_pool' => 'Dividend Pool',
            'win_total' => 'Win Total',
            'no_win_commission' => 'No Win Commission',
            'vip2_recommend_finish_group_total' => 'Vip2 Recommend Finish Group Total',
            'vip2_recommend_finish_group_award' => 'Vip2 Recommend Finish Group Award',
            'card_total' => 'Card Total',
        ];
    }

    public static function getLastOne()
    {
        $model = self::find()
            ->orderBy(['id' => SORT_DESC])
            ->one();

        if (!$model) {
            $model = new self();
        }

        return $model;
    }

    public static function saveData($data)
    {
        $model = self::getLastOne();

        if ($model->load(['MarketingGroup' => $data]) && $model->save()) {
            return true;
        }
    }
}
